package binocle

import (
	"sync/atomic"

	"gddgame.cc/galaxy/utils/def"
)

type Context struct {
	def.Logger
	def.Store

	id    string
	c     *agent
	alloc int32
}

func (context *Context) init(id string) {
	context.id = id
	context.alloc = 0
}

func (context *Context) ID() string {
	return context.id
}

func (context *Context) Alloc() {
	atomic.AddInt32(&context.alloc, 1)
}
func (context *Context) Release() {
	if context.alloc > 0 {
		atomic.AddInt32(&context.alloc, -1)
		return
	}
	context.alloc = -1
	context.c.contextPool.Put(context)
}
